package org.game.msgBuilder;

import java.util.Map;

import org.game.db.bean.Hero;
import org.game.db.vo.EquipmentVO;
import org.game.protobuf.s2c.S2CEquipmentMsg;
import org.game.protobuf.s2c.S2CItemMsg;
import org.game.protobuf.s2c.S2CShareMsg;

import com.google.common.collect.Maps;
import com.sojoys.artifact.tools.ToolDate;

/**
 * 灵装消息封装
 * Created by fxf on 2017/9/27.
 */
public class EquipmentMsgBuilder {

    public static S2CEquipmentMsg.EquipMsg getEquipMsg(EquipmentVO equipment, EquipmentVO oldEquipment) {
        S2CEquipmentMsg.EquipMsg.Builder builder = S2CEquipmentMsg.EquipMsg.newBuilder();
        builder.setEquipment(getPartEquipmentInfo(equipment));
        if (oldEquipment != null) {
            builder.setOldEquipment(getPartEquipmentInfo(oldEquipment));
        }
        return builder.build();
    }

    public static S2CEquipmentMsg.TakeOffMsg getTakeOffMsg(EquipmentVO equipment, Hero hero) {
        S2CEquipmentMsg.TakeOffMsg.Builder builder = S2CEquipmentMsg.TakeOffMsg.newBuilder();
        builder.setSuccess(true);
        return builder.build();
    }

    public static S2CEquipmentMsg.ChangeSpecialAttrMsg getChangeSpecialAttrMsg(int sourceAttrIndex,int attrIndexInCostEquipment) {
        S2CEquipmentMsg.ChangeSpecialAttrMsg.Builder builder = S2CEquipmentMsg.ChangeSpecialAttrMsg.newBuilder();
        builder.setOldAttrIndex(sourceAttrIndex + 1);
        builder.setAttrIndexInCostEquipment(attrIndexInCostEquipment);
        return builder.build();
    }

    public static S2CEquipmentMsg.UpgradeMsg getUpgradeMsg() {
        S2CEquipmentMsg.UpgradeMsg.Builder builder = S2CEquipmentMsg.UpgradeMsg.newBuilder();
        builder.setSuccess(true);
        return builder.build();
    }

    public static S2CEquipmentMsg.ReplaceSpecialAttrMsg getReplaceSpecialAttrMsg() {
        S2CEquipmentMsg.ReplaceSpecialAttrMsg.Builder builder = S2CEquipmentMsg.ReplaceSpecialAttrMsg.newBuilder();
        builder.setSuccess(true);
        return builder.build();
    }

    /**
     * 封装部分装备信息
     * 仅更新变化信息
     */
    private static S2CItemMsg.EquipmentInfo getPartEquipmentInfo(EquipmentVO equipment) {
        S2CItemMsg.EquipmentInfo.Builder equipmentInfoBuilder = S2CItemMsg.EquipmentInfo.newBuilder();
        
        equipmentInfoBuilder.setCt(S2CShareMsg.ChangeType.UPDATE)
                .setId(Long.toString(equipment.getId()))
                .setPosition(equipment.getPosition())
                .setHeroId(Long.toString(equipment.getHeroId()));
        return equipmentInfoBuilder.build();
    }


}
